# Contributor: Bart Ribbers <bribbers@disroot.org>
# Maintainer: team/kde <bribbers@disroot.org>

# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-applications
pkgname=akonadi
pkgver=24.02.2
pkgrel=1
pkgdesc="A cross-desktop storage service for PIM data and meta data providing concurrent read, write, and query access"
# armhf blocked by extra-cmake-modules
# ppc64le, s390x and riscv64 blocked by kaccounts-integration
arch="all !armhf !ppc64le !s390x !riscv64"
url="https://community.kde.org/KDE_PIM"
license="LGPL-2.0-or-later"
depends="
	mariadb
	qt6-qtbase-mysql
	qt6-qtbase-sqlite
	"
depends_dev="
	boost-dev
	kcompletion-dev
	kconfig-dev
	kconfigwidgets-dev
	kcoreaddons-dev
	kcrash-dev
	kdbusaddons-dev
	ki18n-dev
	kiconthemes-dev
	kio-dev
	kitemmodels-dev
	kitemviews-dev
	kwidgetsaddons-dev
	kwindowsystem-dev
	kxmlgui-dev
	libxml2-dev
	qt6-qtbase-dev
	shared-mime-info
	sqlite-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	qt6-qttools-dev
	samurai
	"
checkdepends="
	cmd:dbus-run-session
	xvfb-run
	"
subpackages="$pkgname-dbg $pkgname-dev $pkgname-lang"
_repo_url="https://invent.kde.org/pim/akonadi.git"
source="https://download.kde.org/stable/release-service/$pkgver/src/akonadi-$pkgver.tar.xz"

build() {
	# make -dbg smaller
	export CFLAGS="$CFLAGS -g1"
	export CXXFLAGS="$CXXFLAGS -g1"
	# akonadi recurses while walking e-mail threads, so give it a decent stack
	LDFLAGS="$LDFLAGS -Wl,-z,stack-size=1024768" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_DESIGNERPLUGIN=ON
	cmake --build build
}

check() {
	# akonadixml-xmldocumenttest, mimetypecheckertest and akonadi-mysql-testenvironmenttest are broken
	# All sqlite tests are hanging
	# All mysql tests are broken "Cannot connect to non-local host <hostname>"
	# tagmodeltest fails on 32-bit architectures
	local skipped_tests="("
	local tests="
		akonadixml-xmldocument
		mimetypechecker
		akonadi-mysql-testenvironment
		.*sqlite.*
		.*mysql.*
		tagmodel
		"
	case "$CARCH" in
		s390x) tests="$tests
			AkonadiServer-itemcreatehandler
			AkonadiServer-relationhandler
			" ;;
	esac
	for test in $tests; do
		skipped_tests="$skipped_tests|$test"
	done
	skipped_tests="$skipped_tests)test"
	dbus-run-session xvfb-run ctest --test-dir build --output-on-failure -E "$skipped_tests"
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}
sha512sums="
ca59ba8d69f24296c8ae8f991310df0a5a96f5712924cc1bb6e35c6031d0209d65a91b45fa5c3509c4bc2c0242fc53afe5df69600c9152bec999239798b06067  akonadi-24.02.2.tar.xz
"
